package com.example.jdai.jdai.util;

import android.content.Context;
import android.content.SharedPreferences;
import android.text.TextUtils;

import com.example.jdai.jdai.MyApplication;
import com.example.jdai.jdai.R;
import com.example.jdai.jdai.config.Config;

/**
 * Created by hellopyj on 2017/1/9.
 */

public class DataAll extends BaseData{

    public  static String FIRST_IN="first_in";
    public  static String HAS_LOGIN="has_login";
    public  static String LOGIN_TOKEN="user_token";
    public  static String LOGIN_ID="user_id";
    public static String OK="3";
    public static int SHENGCHA_WWC=0;//未完善
    public static int SHENGCHA=1;//完善
    public static int SHENGCHAING=2;//审查中
    public static int SHANGCHA_OK=3;//审查OK
    public static int SHENCHA_SHIBAI=4;//审查失败
    public static String[] CheckC;
   // public static int WEIWS=0;
   // public static String INFO_STATUS="info_status";
   //public static String PHONE_STATUS="phone_status";
    //public static String CONNECT_STATUS="connect_status";
    public static String ZIMA_STATUS="zima_status";
    //public static String ZX_STATUS="zx_status";
    //public static String ZFB_STATUS="zfb_status";
    //public static String JD_STATUS="jd_status";
    public static String IS_COMMIT="is_commit";
    public static String TMP="tmp";

    public static DataLnfo dataLnfo;//info的数据
    public static DataConnect dataConnect;//connect的数据
    public static DataPhone dataPhone;
    public static DataZx dataZx;
    public static DataZfb dataZfb;
    public static DataJd dataJd;
    public static String TJ="tj_status";//提交
    public static String VERSION="version";
    public static String ABOUT="about";
    public static String COMMIT_C="commit_c";
    public static String COMMIT_V="commit_v";
    public static String MONEY_N="money_n";
    public static String MY_MONEY="my_money";
    public static String REASON_N="reason_n";
    public static String QQ_N="qq_n";
    public DataAll(){
        dataLnfo=new DataLnfo();
        dataConnect=new DataConnect();
        dataPhone=new DataPhone();
        dataZfb=new DataZfb();
        dataJd=new DataJd();
        dataZx=new DataZx();
        CheckC=MyApplication.applicationContext.getResources().getStringArray(R.array.text_check);
        SharedPreferences sp= MyApplication.applicationContext.getSharedPreferences(Config.SP_NAME, Context.CONTEXT_RESTRICTED);
        //data.put(INFO_STATUS,sp.getString(INFO_STATUS,""));
        //data.put(PHONE_STATUS,sp.getString(PHONE_STATUS,""));
        //data.put(CONNECT_STATUS,sp.getString(CONNECT_STATUS,""));
        data.put(ZIMA_STATUS,sp.getString(ZIMA_STATUS,""));
        //data.put(ZX_STATUS,sp.getString(ZX_STATUS,""));
        data.put(LOGIN_TOKEN,sp.getString(LOGIN_TOKEN,""));
        data.put(HAS_LOGIN,sp.getString(HAS_LOGIN,""));
        data.put(TJ,sp.getString(TJ,""));
        data.put(LOGIN_ID,sp.getString(LOGIN_ID,""));
        data.put(IS_COMMIT,sp.getString(IS_COMMIT,"0"));
        data.put(COMMIT_C,sp.getString(COMMIT_C,""));
        data.put(COMMIT_V,sp.getString(COMMIT_V,""));
        data.put(VERSION,sp.getString(VERSION,""));
        data.put(ABOUT,sp.getString(ABOUT,""));
        data.put(MONEY_N,sp.getString(MONEY_N,""));
        data.put(REASON_N,sp.getString(REASON_N,""));
        data.put(QQ_N,sp.getString(QQ_N,""));
        data.put(MY_MONEY,sp.getString(MY_MONEY,((int)(Math.random()*9)*1000+1000)+""));
        data.put(TMP,"");
        //data.put(ZFB_STATUS,sp.getString(ZFB_STATUS,""));
        //data.put(JD_STATUS,sp.getString(JD_STATUS,""));

    }
    public static boolean checkAll(){
        if(dataLnfo.dataCheck()&&
                dataConnect.dataCheck()&&
                (!"0".equals(MyApplication.dataAll.data.get(DataAll.ZIMA_STATUS)))&&
                (!"".equals(MyApplication.dataAll.data.get(DataAll.ZIMA_STATUS)))&&
                (!"0".equals(dataZfb.data.get(DataZfb.ZFB_STATUS)))&&
                (!"".equals(dataZfb.data.get(DataZfb.ZFB_STATUS)))&&
                (!"0".equals(dataLnfo.data.get(DataPhone.PHONE_CODE)))&&
                (!"".equals(dataLnfo.data.get(DataPhone.PHONE_CODE)))

                )
                //&&
                //!"".equals(ZIMA_STATUS)
                {
            return true;
        }
        return false;
    }
    public void clearAll(){
        super.clearAll();
        dataLnfo.clearAll();
        dataConnect.clearAll();
        dataPhone.clearAll();
        dataZfb.clearAll();
        dataJd.clearAll();
        dataZx.clearAll();
        dataJd.clearAll();
    }
    public  static boolean checkCanUp(){
        if(ifOk(DataAll.dataLnfo.data.get(DataLnfo.INFO_STATUS))&&
                ifOk(DataAll.dataConnect.data.get(DataConnect.CT_STATUS))&&
                ifOk(MyApplication.dataAll.data.get(DataAll.ZIMA_STATUS))&&
                ifOk(DataAll.dataZfb.data.get(DataZfb.ZFB_STATUS))&&
                ifOk(DataAll.dataPhone.data.get(DataPhone.PHONE_CODE)))
            return true;
        return false;

    }
    public  static boolean ifOk(String tmp){
        if(!TextUtils.isEmpty(tmp)){
        if(tmp.equals("0")||tmp.equals("2")){
            return false;
        }
        else {
            return true;
        }}
        return false;
    }
    @Override
    public boolean saveAll(){
        super.saveAll();
        dataLnfo.saveAll();
        dataConnect.saveAll();
        dataZfb.saveAll();
        dataPhone.saveAll();
        return true;
    }


}
